﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nvn.Core.MVP;
using Hutech.CRM.Library.Views;
using Hutech.CRM.Library.Models.BusinessAccessLayer;
using Hutech.CRM.Library.Models.Entities;
using nvn.Library.Patterns;

namespace Hutech.CRM.Library.Presenters
{
    public class AddNewCriterionCustomerPresenter : BasePresenter<IAddNewCriterionCustomerView>
    {
        #region First Description
        public AddNewCriterionCustomerPresenter(IAddNewCriterionCustomerView view)
            : base(view)
        {
            this.view.FristLoadEventHandler += new EventHandler<EventArgs>(view_FristLoadEventHandler);
            this.view.Save_Click+=new EventHandler<SaveEventAgrs<CriterionCustomer>>(view_Save_Click);
            this.view.Exit_Click += new EventHandler<EventArgs>(view_Exit_Click);
        }
       
        #endregion

        #region All Event
        void view_Exit_Click(object sender, EventArgs e)
        {
            
        }
        void view_Save_Click(object sender, SaveEventAgrs<CriterionCustomer> e)
        {
            CriterionCustomerBAL itemBAL = new CriterionCustomerBAL();
            
            CriterionCustomer item = e.myType;
            item.IsActive = true;
            item.LastUpdatedDate = DateTime.Now;
            //con thieu do uu tien va icon

            if (itemBAL.Save(item))
            {
                RefreshAllControl();
                view.UpdatePopup = true;
                view.ShowPopup = false;
            }
            else 
            { 
            }
        }

        void view_FristLoadEventHandler(object sender, EventArgs e)
        {
            view.HeaderPopup = "Create new";
            view.GroupLevelCustomers = LoadGroupLevelCustomer();
            //view.ShowPopup = true;
        }
        #endregion

        #region private method
        List<TowTypeParameters<Guid,string>> LoadGroupLevelCustomer()
        {
            CriterionCustomerBAL itemBAL = new CriterionCustomerBAL();
            return itemBAL.GetGroupLevelCustomers();
        }
        void RefreshAllControl() 
        {
            view.GroupLevelCustomers = LoadGroupLevelCustomer();
            view.CriterionName = string.Empty;
        }
        #endregion
    }
}
